/*
 * Logger.cpp
 *
 *  Created on: Sep 10, 2012
 *      Author: nam20485
 */

#include "Logger.h"

// Stream* storage
/* static */ Stream* Logger::m_apStreams[Logger::MAX_STREAMS] =
{
		NULL_STREAM,
		NULL_STREAM,
		NULL_STREAM,
		NULL_STREAM,
		NULL_STREAM
};

/* static */ int Logger::addStream(Stream* pStream)
{
	//m_streams.Add(pStream);
	for (int i = 0; i < MAX_STREAMS; i++)
	{
		if (Logger::m_apStreams[i] == NULL_STREAM)
		{
			Logger::m_apStreams[i] = pStream;
			return i;
		}
	}
	return -1;
}

/* static */ void Logger::removeStream(int index)
{
	Logger::m_apStreams[index] = NULL_STREAM;
}

void Logger::log(const uint8_t c)
{
	for (int i = 0; i < MAX_STREAMS; i++)
	{
		Stream* pStream = Logger::m_apStreams[i];
		if (pStream != 0)
		{
			pStream->write(c);
		}
	}
}

/* static */ void Logger::log(const String& s)
{
	for (int i = 0; i < MAX_STREAMS; i++)
	{
		Stream* pStream = Logger::m_apStreams[i];
		if (pStream != 0)
		{
			unsigned char szBuff[s.length()+1];
			s.getBytes(szBuff, s.length());
			pStream->write((const char*) szBuff);

		}
	}
}

/* static */ void Logger::log(const char* sz)
{
	for (int i = 0; i < MAX_STREAMS; i++)
	{
		Stream* pStream = Logger::m_apStreams[i];
		if (pStream != 0)
		{
			pStream->write(sz);
		}
	}
}

